using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

[Serializable]
public class Parameter
{
    public float RunSpeed;
    public float JumpSpeed;
    public int JumpCount;
    public float DoubleJumpSpeed;

    public Transform playertrans;
    public Rigidbody2D Player;
    public Animator animator;

    public Transform Feet;
    public LayerMask layerGround;
}

public class FSM : MonoBehaviour
{
    public Parameter parameter;
    public IState currentState;
    public Dictionary<StateType, IState> states = new Dictionary<StateType, IState>();

    protected virtual void Start()
    {
        states.Add(StateType.Appearing,new Appearing(this));
        states.Add(StateType.Idle, new Idle(this));
        states.Add(StateType.Runing, new Running(this));
        states.Add(StateType.Jump, new Jumping(this));
        states.Add(StateType.DoubleJumping, new DoubleJumping(this));
        states.Add(StateType.Falling, new Falling(this));
        states.Add(StateType.Hurting, new Hurting(this));
        TransitionState(StateType.Appearing);
    }

    protected virtual void Update()
    {
        currentState.OnUpdate();
    }

    public void TransitionState(StateType type)
    {
        if (currentState != null)
        {
            currentState.OnExit();
        }
        currentState = states[type];
        currentState.OnEnter();
    }

    public void PlayAnimation(string animation)
    {
        parameter.animator.Play(animation);
    }
}

public static class FSM_AniMationName
{
    public static string Appearing = "Appearing";
    public static string Idle = "Idle";
    public static string Run = "Run";
    public static string Jump = "Jump";
    public static string DoubleJump = "DoubleJump";
    public static string Fall = "Full";
    public static string Hurt = "Hit";
}

public enum StateType
{
    Appearing,
    Idle,
    Runing,
    Jump,
    DoubleJumping,
    Falling,
    Hurting
}
